<template>
  <div class="recruitment">
    <van-nav-bar title="招聘" left-text="" fixed placeholder left-arrow @click-left="$publicObj.getReturn"></van-nav-bar>
    <div class="content">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="(item, index) in swiperArr" :key="index">
          <a :href="item.linkUrl">
            <img :src="$publicObj.urlImg(item.url)" alt="" />
          </a>
        </van-swipe-item>
      </van-swipe>
      <div class="contentss">
        <div class="contents-center">
          <div class="contents-center-item" @click="$router.push({path:'/releasepromotion',query:{msg:1}})">
            <div class="imgs">
              <img src="../../assets/images/invite/tuiguang.png" alt="">
              <p>推广招聘</p>
            </div>
          </div>
          <div class="contents-center-item" @click="goTo()">
            <div class="imgs">
              <img src="../../assets/images/invite/fabu.png" alt="">
              <p>发布招聘</p>
            </div>
          </div>
          <div class="contents-center-item" @click="$router.push({path:'/recruitmentmaterial'})">
            <div class="imgs">
              <img src="../../assets/images/detail/sucai.png" alt="">
              <p>招聘文案</p>
            </div>
          </div>
        </div>
      </div>
      <div class="contents">
        <div class="contents-title">
          <img src="../../assets/images/invite/shu.png" alt="">
          <span>招聘统计</span>
        </div>
        <div class="contents-center">
          <div class="contents-center-item1">
            <span>招聘总数</span>
            <p>{{tuiguang.publishSum || 0}}人</p>
          </div>
          <div class="contents-center-item2">
            <span>剩余赏金</span>
            <p>{{tuiguang.moneyReward || 0}}元</p>
          </div>
          <div class="contents-center-item3">
            <span>已发出赏金</span>
            <p>{{tuiguang.transmit || 0}}人</p>
          </div>
        </div>
      </div>
      <div class="tabs">
        <van-tabs v-model="active" color="#477fe6" title-active-color="#477fe6" @change="getRecruits($event)">
          <van-tab v-for="(item,index) in tabs" :key="index" :title="item.title">
             <van-list
                v-model="loading"
                :finished="finished"
                finished-text="没有更多了"
                @load="onLoad"
              >
                <div class="contentsss">
              <div class="contents-center" v-if="recruitmentArr.length!=0">
                <div class="contents-center-item" v-for="(item,index) in recruitmentArr" :key="index" @click="$router.push({path:'/recruitmentdetails',query:{id:item.id,type:2}})">
                  <div class="imgs">
                    <img src="../../assets/images/task/getMoney.png" alt="" class="money" v-show="item.type == 9" />
                    <img :src="item.cover" alt="">
                  </div>
                  <div class="contents-b-item">
                    <div class="left">
                      <div class="title">
                        <h3>{{item.title}}</h3>
                      </div>
                      <div class="content">
                        <p>{{item.describes}}</p>
                      </div>
                      <div class="contents-text">
                        <div class="contents-text-item">
                          <img src="../../assets/images/invite/fenxiang.png" alt="">
                          <p>转发:{{item.share || 0}}次</p>
                        </div>
                        &nbsp;&nbsp;
                        <div class="contents-text-item" @click.stop="goDetail(item)">
                          <img src="../../assets/images/invite/yuedu.png" alt="">
                          <p>阅读:{{item.score || 0}}次</p>
                        </div>
                        &nbsp;&nbsp;
                        <div class="contents-text-item">
                          <p style="margin-top:2px">{{item.gmtCreate.substring(0,11)}}</p>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <van-empty description="当前暂无招聘内容~" class="custom-image" :image="require('../../assets/dafault/noinvite.png')" v-else>
                <van-button round type="danger" class="bottom-button" @click="goAdd">去新建招聘</van-button>
              </van-empty>
                </div>
             </van-list>
          </van-tab>
        </van-tabs>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "recruitment",
  data () {
    return {
      swiperArr: [], //轮播图
      recruitmentArr: [],
      tuiguang: {},
      active: "",
      loading: false, //加载状态
      finished: false, //完成
      page: 1, //页数
      limit: 8, //条数
      totalPage: "", //总页数
      isPower: 1,
      tabs: [
        { title: "平台赏金招聘", index: 1 },
        { title: "内部推广招聘", index: 2 },
        { title: "团队免费招聘", index: 3 },
        { title: "团队推广招聘", index: 3 }
      ],
      wxUserInfo:{},
    }
  },
  async mounted () {
    this.wxUserInfo = JSON.parse(sessionStorage.getItem("userWxData"));
    this.isCustomer();
    //获取轮播图数据
    this.getswiperArr();
    this.getRecruits(0);
    this.getPromotionStatistics();
  },
  methods: {
      //触底下一页
    onLoad() {
      if (this.page >= this.totalPage) {
        this.finished = true;
        return;
      }
      this.page++;

      this.getRecruits();
      // 加载状态结束
      this.loading = false;
    },
    // yuedu
    goDetail(item){
      if (this.isPower == 3) return;
      let obj = {
        cover:item.cover,
        title:item.title,
        description:item.describes,
        share:item.share,
        score:item.score,
        gmtCreate:item.gmtCreate,
      };
      sessionStorage.setItem("taskDetail", JSON.stringify(obj));
      this.$router.push(`/taskDetails?id=${item.id}&title=招聘`);
    },
    //判断是否有权限创建
    async isCustomer () {
      let account = sessionStorage.getItem("agentId");
      let res = await this.$api.isCustomer({
        openId: this.wxUserInfo.openid,
        account,
        id: this.$store.state.userInfo.id,
        phone: this.$store.state.userInfo.phone,
      });
      this.isPower = res.data;
    },
    // 推广和发布跳转
    goTo () {
      if (this.isPower == 1 || this.isPower == 2) {
        this.$router.push({ path: '/releasepromotion', query: { msg: 2 } })
      } else {
        this.$router.push("/mineInstructions");
        this.$toast("你没有权限操作，请联系管理员")
      }
    },
    //去创建
    goAdd () {
      this.$router.push({ path: "/addRecruitment" });
    },
    async getPromotionStatistics () {
      let obj = {
        account: sessionStorage.getItem("agentId"),
        tableType: 15
      }
      let res = await this.$api.getPromotionStatistics(obj);
      this.tuiguang = res.data
    },
    // 获取招聘
    async getRecruits (e) {
      let obj = {
        openId: this.wxUserInfo.openid,
        name: this.wxUserInfo.nickname,
        image: this.wxUserInfo.headimgurl,
        sex: this.wxUserInfo.sex,
        city: this.wxUserInfo.city,
        province: this.wxUserInfo.province,
      };
      if(e==0){
        obj.type = 10
        obj.status = 2
        obj.account = sessionStorage.getItem("agentId")
        obj.page = this.page
        obj.limit =this.limit
        obj.tabelType=15
      }else if (e == 1) {
        obj.type = 9
        obj.status = 2
        obj.account = sessionStorage.getItem("agentId")
        obj.page = this.page
        obj.limit =this.limit
        obj.tabelType=15
      } else if (e == 2) {
        obj.type = 8
        obj.status = 2
        obj.account = sessionStorage.getItem("agentId")
        obj.page = this.page
        obj.limit =this.limit
        obj.tabelType=15
      } else if (e == 3) { 
        obj.type = 9
        obj.status = 2
        obj.account = sessionStorage.getItem("agentId")
        obj.page = this.page
        obj.limit =this.limit
        obj.tabelType=15
      }
      let res = await this.$api.getRecruit(obj);
        //判断是否是第一页
      if (this.page == 1) {
        this.recruitmentArr = res.data.list || [];
      } else {
        this.recruitmentArr.push(...res.data.list);
      }
      this.totalPage = res.data.totalPage;
    },
    //获取轮播图数据
    getswiperArr () {
      this.swiperArr = this.$store.state.userInfo.systemCoverList.map(
        (item) => {
          return { url: item.url, linkUrl: item.linkUrl };
        }
      );
    },
  }
}
</script>
<style lang="less" scoped>
/deep/.van-empty__image {
  width: 166px;
  height: 139px;
}
/deep/.van-tab__text {
  font-size: 12px;
}
.bottom-button {
  width: 130px;
  height: 34px;
  background-color: #477fe6;
  border-radius: 17px;
  border: none;
  font-size: 13px;
  color: #ffffff;
}
.content {
  padding-bottom: 50px;
}
.contents {
  .contents-title {
    display: flex;
    padding: 20px;
    img {
      width: 4px;
      height: 20px;
    }
    span {
      margin: 0.5px 10px;
      font-size: 14px;
      color: #3b447a;
    }
  }
  .contents-center {
    display: flex;
    justify-content: center;
    margin: 0 15px;
    .contents-center-item1 {
      width: 32%;
      height: 80px;
      background: url('../../assets/images/invite/bg1.png');
      background-size: 100%;
      background-repeat: no-repeat;
      color: #fff;
      text-align: center;
      line-height: 30px;
      span {
        display: block;
        font-size: 12px;
        margin-top: 3px;
      }
      p {
        display: block;
        font-size: 18px;
      }
    }
    .contents-center-item2 {
      width: 32%;
      height: 80px;
      background: url('../../assets/images/invite/bg2.png');
      background-size: 100%;
      background-repeat: no-repeat;
      margin-left: 5px;
      color: #fff;
      text-align: center;
      line-height: 30px;
      span {
        display: block;
        font-size: 12px;
        margin-top: 3px;
      }
      p {
        display: block;
        font-size: 18px;
      }
    }
    .contents-center-item3 {
      width: 32%;
      height: 80px;
      background: url('../../assets/images/invite/bg3.png');
      background-size: 100%;
      background-repeat: no-repeat;
      margin-left: 5px;
      color: #fff;
      text-align: center;
      line-height: 30px;
      span {
        display: block;
        font-size: 12px;
        margin-top: 3px;
      }
      p {
        display: block;
        font-size: 18px;
      }
    }
  }
}
.contentss {
  .contents-center {
    display: flex;
    margin: 10px;
    .contents-center-item {
      width: 33.3%;
      height: 90px;
      background: #ffffff;
      border-radius: 10px;
      box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.16);
      margin: 5px 5px;
      .imgs {
        text-align: center;
        img {
          width: 40px;
          height: 40px;
          margin-top: 10px;
        }
      }
    }
  }
}
.contentsss {
  padding-bottom: 50px;
  .contents-center {
    .contents-center-item {
      display: flex;
      padding: 12px;
      border-bottom: 1px solid ghostwhite;
      .imgs {
        flex: 1;
        width: 90px;
        height: 90px;
        margin-right: 15px;
        position: relative;
        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
        .money {
          width: 35px;
          height: 35px;
          position: absolute;
          right: 0;
          top: 0;
          border-radius: none;
        }
      }
      .contents-b-item {
        flex: 3;
        .left {
          .title {
            h3 {
              display: block;
              font-size: 14px;
              color: #333333;
            }
          }
          .content {
            margin-top: 2px;
            p {
              font-size: 11px;
              color: #999999;
              height: 30px;
              display: -webkit-box;
              overflow: hidden;
              -webkit-box-orient: vertical;
              text-overflow: ellipsis;
              -webkit-line-clamp: 2;
            }
          }

          .contents-text {
            display: flex;
            justify-content: space-between;
            font-size: 12px;
            color: #999;
            .contents-text-item {
              display: flex;
              justify-content: space-between;
              margin-top: -30px;
              img {
                width: 12px;
                height: 12px;
                margin-top: 2px;
              }
              p {
                margin-left: 5px;
              }
            }
          } 
        }
      }
    }
  }
}
.my-swipe {
  height: 150px;
  width: 90%;
  box-sizing: border-box;
  margin: 5px auto;

  .van-swipe-item {
    img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>